package controle;
import vue.panneau1.*;
import modele.*;
import java.awt.Color;
import java.awt.event.*;

public class ControleActionEquation3D implements ActionListener
{
	private Interface3DZone1 zone3D;
	
	public ControleActionEquation3D(Interface3DZone1 zone3D)
	{
		this.zone3D = zone3D;		
	}

	public void actionPerformed(ActionEvent e) 
	{
		String cmd = e.getActionCommand();
		
		if(cmd.equals("choisir_libelle"))
		{
			new PopupChoixLibelleVariables3D(zone3D);
		}
		
		if(cmd.equals("choisir_couleur"))
		{
			zone3D.choisirCouleur();
		}
		
		if(cmd.equals("ajouter"))
		{
			String sx1,sx2,sx3,pdt,op;
			Color couleur;
			
			sx1 = zone3D.getValeurContrainte("x1");
			sx2 = zone3D.getValeurContrainte("x2");
			sx3 = zone3D.getValeurContrainte("x3");
			pdt = zone3D.getValeurContrainte("partieD");
			op = zone3D.getOperateur();
			couleur = zone3D.getCouleurChoisie();
			
			if(!(sx1.equals("") || sx2.equals("") || sx3.equals("") || pdt.equals("")))
			{	
				float x1 = zone3D.getFloatContrainte("x1");
				float x2 = zone3D.getFloatContrainte("x2");
				float x3 = zone3D.getFloatContrainte("x3");
				float partieD = zone3D.getFloatContrainte("partieD");
				
				if(!(x1 == 0 && x2 == 0)) 
				{
					zone3D.ajouterEquation(new Equation3D(x1,x2,x3,op,partieD,couleur,""));
				}
			}
		}
		
		if(cmd.equals("supprimer"))
		{
			zone3D.supprimerEquation();			
		}
		
		if(cmd.equals("optimiser"))
		{
			String sx1,sx2,sx3,sc;
			
			sx1 = zone3D.getOptValeurX1X2X3("x1");
			sx2 = zone3D.getOptValeurX1X2X3("x2");
			sx3 = zone3D.getOptValeurX1X2X3("x3");
			sc = zone3D.getOptChoix();
			
			if(!(sx1.equals("") || sx2.equals("") || sx3.equals("")))
			{	
				float x1 = zone3D.getOptFloatX1X2X3("x1");
				float x2 = zone3D.getOptFloatX1X2X3("x2");
				float x3 = zone3D.getOptFloatX1X2X3("x3");
				
				boolean optimiser = new Boolean("");
				if(sc.equals("Minimiser"))
				{
					optimiser = false;
				}
				if(sc.equals("Maximiser"))
				{
					optimiser = true;
				}
				
				zone3D.optimiser(new FonctionAOptimiser3D(x1,x2,x3,optimiser));
			}			
		}
	}
}
